# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: xguo

from coin.exchange.base.kr_rest.product import NativeProduct, NormProduct
from coin.exchange.gemini_v1.kr_rest.constants import (symbol_list, quote_currency_list, coin_list)


# Gemini uses upper case currency symbols in the json message, and lower case
# product symbols. For example, product symbol btcusd is lower case,
# but currency symbol USD is upper case.
def from_native_currency(currency):
  return currency


def to_native_currency(currency):
  assert currency in coin_list
  return currency


class GeminiProduct(NativeProduct):
  _exchange = "Gemini"

  def __init__(self, base, quote):
    assert base.upper() == base
    assert quote.upper() == quote
    assert base in coin_list
    assert quote in quote_currency_list
    assert base != quote
    native_symbol = "%s%s" % (base.lower(), quote.lower())
    NativeProduct.__init__(self, base, quote, native_symbol)

  @classmethod
  def FromProduct(cls, product):
    assert type(product) == NormProduct
    return GeminiProduct(product.base, product.quote)

  @classmethod
  def FromStr(cls, product):
    assert type(product) is str
    if product in symbol_list:
      base, quote = product[:3], product[3:]
      base = base.upper()
      quote = quote.upper()
    else:
      pair = product.split('-')
      assert len(pair) == 2
      base, quote = pair
    return GeminiProduct(base, quote)
